package com.fanfan.SmartPensionSystembackend.service.impl;

import com.fanfan.SmartPensionSystembackend.entity.DailyDataBaseInfo;
import com.fanfan.SmartPensionSystembackend.entity.DailyDataDailyData;
import com.fanfan.SmartPensionSystembackend.entity.DailyDataTijianData;
import com.fanfan.SmartPensionSystembackend.mapper.DailyDataMapper;
import com.fanfan.SmartPensionSystembackend.service.DailyDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description DailyDataServiceImpl
 * @Author Guangdi Chen
 * @Date 2025-03-19
 */
@Service
public class DailyDataServiceImpl implements DailyDataService {

    @Autowired
    private DailyDataMapper dailyDataMapper;

    // 获取全部用户信息
    @Override
    public List<DailyDataBaseInfo> getAllDailyData() {
        return dailyDataMapper.getAllDailyData(); // 调用Mapper获取数据
    }

    //根据userId获取用户信息
    @Override
    public DailyDataBaseInfo screenDailyDataWithId(String userId) {
        return dailyDataMapper.screenDailyDataWithId(userId);
    }
    //根据地址获取用户信息
    @Override
    public List<DailyDataBaseInfo> screenDailyDataWithAddress(String buildingNo, String floorNo, String roomNo) {
        return dailyDataMapper.screenDailyDataWithAddress(buildingNo, floorNo, roomNo);
    }
    // 插入日常数据
    @Override
    public int insertDailyData(DailyDataDailyData dailyData) {
        // 生成四位数的recordId
        String lastRecordId = dailyDataMapper.getLastRecordId();
        int newRecordId = lastRecordId == null ? 1 : Integer.parseInt(lastRecordId) + 1;
        dailyData.setRecordId(String.format("%04d", newRecordId));
        return dailyDataMapper.insertDailyData(dailyData);
    }

    // 插入体检数据
    @Override
    public int insertTijianData(DailyDataTijianData dailyData) {
        // 生成四位数的reportNo
        String lastReportNo = dailyDataMapper.getLastReportNo();
        int newReportNo = lastReportNo == null ? 1 : Integer.parseInt(lastReportNo) + 1;
        dailyData.setReportNo(String.format("%04d", newReportNo));
        return dailyDataMapper.insertTijianData(dailyData);
    }
}